package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.base.BaseDao;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.dao.UserFollowDao;
import com.atguigu.entity.UserFollow;
import com.atguigu.service.DictService;
import com.atguigu.service.HouseService;
import com.atguigu.service.UserFollowService;
import com.atguigu.vo.UserFollowVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lhh
 * @ClassName UserFollowServiceImpl
 * @date 2022/9/24 11:47
 */
@Service(interfaceClass = UserFollowService.class)
@Transactional
public class UserFollowServiceImpl extends BaseServiceImpl<UserFollow> implements UserFollowService {

    @Autowired
    private UserFollowDao userFollowDao;

    @Reference
    private DictService dictService;

    @Override
    protected BaseDao<UserFollow> getEntityDao() {
        return  userFollowDao;
    }

    public boolean isFollow(Long userId, Long houseId) {

        Integer row=userFollowDao.countByUserIdAndHouseId(userId,houseId);

        if(row>0){
            return true;
        }
        return false;
    }

    public PageInfo<UserFollowVo> getFollowList(Integer pageNum, Integer pageSize, Long userId) {
        PageHelper.startPage(pageNum,pageSize);
        Page<UserFollowVo> page=userFollowDao.getFollowList(userId);
        List<UserFollowVo> followVoList = page.getResult();
        for (UserFollowVo followVo : followVoList) {
            //楼层
            String floorName = dictService.getNameById(followVo.getFloorId());
            followVo.setFloorName(floorName);
            //朝向：
            String directionName = dictService.getNameById(followVo.getDirectionId());
            followVo.setDirectionName(directionName);
            //户型
            String houseTypeName = dictService.getNameById(followVo.getHouseTypeId());
            followVo.setHouseTypeName(houseTypeName);
        }
        return new PageInfo<UserFollowVo>(page.getResult());
    }
}
